using System;
using System.IO;
using System.Text;

namespace ThalesHsmComms
{
	public class GenerateBDKMsg : WSMMsg
	{

		public String Bdk{private set;get;}
		public String checkDigits{private set;get;}

		public GenerateBDKMsg()
			:base("A0")
		{
		}

		override protected void Encode() 
		{
			
			StringBuilder data = new StringBuilder();
			
			try 
			{
				// pack command code
				data.Append(this.commandCode);
				
				// pack mode
				data.Append("0");
				
				// pack keytype
				data.Append("009");
				
				// pack keyscheme
				data.Append("U");
				
				this.requestData = Encoding.ASCII.GetBytes(data.ToString());
				
			} 
			catch (IOException ex) 
			{
				Console.WriteLine(ex);
			}
		}

		override protected void Decode()
		{	
			// get zpk under lmk
			this.GetNextBytesFromResponse(1);
			this.Bdk = this.GetNextBytesFromResponse(32);
			
			// get check digits
			this.checkDigits = this.GetNextBytesFromResponse(6);
			
		}

	}
}

